package com.outsider.note.controller;

import java.util.List;

import com.jfinal.aop.Before;
import com.jfinal.core.Controller;
import com.jfinal.plugin.activerecord.Page;
import com.outsider.interceptor.ResponseHeaderInterceptor;
import com.outsider.note.dao.TextNote;
import com.outsider.note.service.TextNoteService;
import com.outsider.util.Const;
import com.outsider.weixin.dao.User;

@Before(ResponseHeaderInterceptor.class)
public class TextNoteController extends Controller{
	private TextNoteService textNoteService=new TextNoteService();

    //flag=0 返回全部 
    //flag=1 返回未生效的list
    public void getNote(){
    	int flag=getParaToInt("flag");
    	String openID=getPara(Const.OPEN_ID);
		int page=getParaToInt("page");
		int row=getParaToInt("row");
		System.out.println(page+" "+row);
    	int userID=User.dao.findIDbyOpenID(openID);
    	Page<TextNote> list=null;
    	if (flag==0)
    		list=TextNote.dao.findAllNotePage(page,row,userID);
    	else
    		list=TextNote.dao.findNotExpiredNotePage(page,row,userID);
    	renderJson("page", list);
    }
    
    public void delete(){
    	int ID=getParaToInt();
    	textNoteService.deleteTextNote(TextNote.dao.findById(ID));
    	renderJson(Const.RESULT, Const.SUCCESS);
    }
    public void update(){
    	getModel(TextNote.class).update();
    	renderJson(Const.RESULT, Const.SUCCESS);
    }
    
}
